package com.gm;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-12-24
 * Time: 下午3:50
 * To change this template use File | Settings | File Templates.
 */
public class SocketTest {
    public static void main(String[] args) {
        //Socket socket= null;
        try {
            Socket socket = new Socket("127.0.0.1",123);
            try{
                InputStream inputStream=socket.getInputStream();
                Scanner scanner=new Scanner(inputStream);

                while(scanner.hasNextLine()){
                    String line=scanner.nextLine();
                    System.out.println(line);
                }
            }
            finally {
                socket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}
